<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">
        <!-- 用了一个行列布局 -->
        <TreeTool :tree="companyInfo" />
        <!-- 树形控件 -->
        <el-tree :data="treeData">
          <TreeTool slot-scope="{ data }" :tree="data" @on-delete="loadDapartement" @on-add="onadd" />
        </el-tree>
        <!-- 对话框  -->
        <DeptsDialog :showdialog="ondialogVisible" :treenode="treenode" @close="ondialogVisible = false" />
      </el-card>
    </div>
  </div>
</template>

<script>
import { getDapartement } from '@/api/departemt'
import { listToTree } from '@/utils/departments'
import TreeTool from './components/tree-tools.vue'
import DeptsDialog from './components/depts-dialog.vue'
export default {
  name: 'Departments',
  components: {
    TreeTool,
    DeptsDialog
  },
  data() {
    return {
      treeData: [],
      companyInfo: {
        name: '',
        manager: '负责人'
      },
      ondialogVisible: false,
      treenode: {}
    }
  },

  created() {
    this.loadDapartement()
  },

  methods: {
    onadd(e) {
      this.ondialogVisible = true
      this.treenode = e
    },
    async loadDapartement() {
      const res = await getDapartement()
      this.treeData = listToTree(res.depts, '')
      this.companyInfo.name = res.companyName
      console.log(res)
    }
  }
}
</script>

<style scoped lang='scss'>
.tree-card {
  // padding: 30px  140px;
  font-size:14px;
}
.dashboard-container{
  .el-row{
    width: 100%;
  }
}
</style>
